require("json")
local udata = {}
function push(v)
    if type(v) == 'table' then
        temp = {
            val = v,
            dat = os.time()
        }
        table.insert(udata, temp)
    else
        temp = {
            val = {v},
            dat = os.time()
        }
        table.insert(udata, temp)
    end
    return udata
end
function pull()
    local v = udata[#udata]
    table.remove(udata)
    return v
end

-- for i = 1, 10, 1 do push(i) end

--[[ print(pull().val[1], #udata)
print(pull().val[1], #udata)
print(pull().val[1], #udata)
print(pull().val[1], #udata)
print(pull().val[1], #udata) ]]
function output(...) print('size:' .. #udata, unpack(udata), json.encode(udata)) end
udata = {}

for i = 1, 99 do table.insert(udata, {dat=os.time(), val={i,i}}) end
len = #udata
print("len="..len)
for i = 1, len, 10 do
    --print(i, i + 9)
    temp = {unpack(udata, i, i + 9)}
    print("data:"..json.encode(temp))
    if (i+10)<= len then print("wait...") end
end